import { type App } from 'vue'
import { useAuthStore } from '@/store/auth'
import { find } from 'lodash'

export const authBtn = (app: App<Element>) => {
  app.directive('auth', {
    mounted (el, binding) {
      const { allAuth } = useAuthStore()
      // console.log('v-aut 自定义指令', binding.value, allAuth)
      // 根据后端返回的 权限列表 结合 调用自定义指令时传入的权限标识 判断元素 是否显示
      if (find(allAuth, { action: binding.value })) {
        el.style.display = 'block'
      } else {
        el.style.display = 'none'
      }
    }
  })
}
